home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libmpeg_src.lha / motionvector.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-25  |  5.9 KB  |  197 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <config.h>
  22. #include "video.h"
  23. #include "proto.h"
  24. #include "util.h"
  25.  
  26.  
  27. /*
  28.  *--------------------------------------------------------------
  29.  *
  30.  * ComputeVector --
  31.  *
  32.  *    Computes motion vector given parameters previously parsed
  33.  *      and reconstructed.
  34.  *
  35.  * Results:
  36.  *      Reconstructed motion vector info is put into recon_* parameters
  37.  *      passed to this function. Also updated previous motion vector
  38.  *      information.
  39.  *
  40.  * Side effects:
  41.  *      None.
  42.  *
  43.  *--------------------------------------------------------------
  44.  */
  45.  
  46. #define ComputeVector(recon_right_ptr, recon_down_ptr, recon_right_prev, recon_down_prev, f, full_pel_vector, motion_h_code, motion_v_code, motion_h_r, motion_v_r)                \
  47.                                     \
  48. {                                    \
  49.   int comp_h_r, comp_v_r;                        \
  50.   int right_little, right_big, down_little, down_big;            \
  51.   int max, min, new_vector;                        \
  52.                                     \
  53.   /* The following procedure for the reconstruction of motion vectors     \
  54.      is a direct and simple implementation of the instructions given    \
  55.      in the mpeg December 1991 standard draft.                 \
  56.   */                                    \
  57.                                     \
  58.   if (f == 1 || motion_h_code == 0)                    \
  59.     comp_h_r = 0;                            \
  60.   else                                     \
  61.     comp_h_r = f - 1 - motion_h_r;                    \
  62.                                     \
  63.   if (f == 1 || motion_v_code == 0)                    \
  64.     comp_v_r = 0;                            \
  65.   else                                     \
  66.     comp_v_r = f - 1 - motion_v_r;                    \
  67.                                     \
  68.   right_little = motion_h_code * f;                    \
  69.   if (right_little == 0)                        \
  70.     right_big = 0;                            \
  71.   else {                                \
  72.     if (right_little > 0) {                        \
  73.       right_little = right_little - comp_h_r;                \
  74.       right_big = right_little - 32 * f;                \
  75.     }                                    \
  76.     else {                                \
  77.       right_little = right_little + comp_h_r;                \
  78.       right_big = right_little + 32 * f;                \
  79.     }                                    \
  80.   }                                    \
  81.                                     \
  82.   down_little = motion_v_code * f;                    \
  83.   if (down_little == 0)                            \
  84.     down_big = 0;                            \
  85.   else {                                \
  86.     if (down_little > 0) {                        \
  87.       down_little = down_little - comp_v_r;                \
  88.       down_big = down_little - 32 * f;                    \
  89.     }                                    \
  90.     else {                                \
  91.       down_little = down_little + comp_v_r;                \
  92.       down_big = down_little + 32 * f;                    \
  93.     }                                    \
  94.   }                                    \
  95.                                       \
  96.   max = 16 * f - 1;                            \
  97.   min = -16 * f;                            \
  98.                                     \
  99.   new_vector = recon_right_prev + right_little;                \
  100.                                     \
  101.   if (new_vector <= max && new_vector >= min)                \
  102.     *recon_right_ptr = recon_right_prev + right_little;            \
  103.                       /* just new_vector */                \
  104.   else                                    \
  105.     *recon_right_ptr = recon_right_prev + right_big;            \
  106.   recon_right_prev = *recon_right_ptr;                    \
  107.   if (full_pel_vector)                            \
  108.     *recon_right_ptr = *recon_right_ptr << 1;                \
  109.                                     \
  110.   new_vector = recon_down_prev + down_little;                \
  111.   if (new_vector <= max && new_vector >= min)                \
  112.     *recon_down_ptr = recon_down_prev + down_little;            \
  113.                       /* just new_vector */                \
  114.   else                                    \
  115.     *recon_down_ptr = recon_down_prev + down_big;            \
  116.   recon_down_prev = *recon_down_ptr;                    \
  117.   if (full_pel_vector)                            \
  118.     *recon_down_ptr = *recon_down_ptr << 1;                \
  119. }
  120.  
  121. /*
  122.  *--------------------------------------------------------------
  123.  *
  124.  * ComputeForwVector --
  125.  *
  126.  *    Computes forward motion vector by calling ComputeVector
  127.  *      with appropriate parameters.
  128.  *
  129.  * Results:
  130.  *    Reconstructed motion vector placed in recon_right_for_ptr and
  131.  *      recon_down_for_ptr.
  132.  *
  133.  * Side effects:
  134.  *      None.
  135.  *
  136.  *--------------------------------------------------------------
  137.  */
  138.  
  139. void 
  140. ComputeForwVector(recon_right_for_ptr, recon_down_for_ptr)
  141.      int *recon_right_for_ptr;
  142.      int *recon_down_for_ptr;
  143. {
  144.  
  145.   Pict *picture;
  146.   Macroblock *mblock;
  147.  
  148.   picture = &(curVidStream->picture);
  149.   mblock = &(curVidStream->mblock);
  150.  
  151.   ComputeVector(recon_right_for_ptr, recon_down_for_ptr,
  152.         mblock->recon_right_for_prev, 
  153.         mblock->recon_down_for_prev,
  154.         picture->forw_f, picture->full_pel_forw_vector,
  155.         mblock->motion_h_forw_code, mblock->motion_v_forw_code,
  156.         mblock->motion_h_forw_r, mblock->motion_v_forw_r); 
  157. }
  158.  
  159.  
  160. /*
  161.  *--------------------------------------------------------------
  162.  *
  163.  * ComputeBackVector --
  164.  *
  165.  *    Computes backward motion vector by calling ComputeVector
  166.  *      with appropriate parameters.
  167.  *
  168.  * Results:
  169.  *    Reconstructed motion vector placed in recon_right_back_ptr and
  170.  *      recon_down_back_ptr.
  171.  *
  172.  * Side effects:
  173.  *      None.
  174.  *
  175.  *--------------------------------------------------------------
  176.  */
  177.  
  178. void 
  179. ComputeBackVector(recon_right_back_ptr, recon_down_back_ptr)
  180.      int *recon_right_back_ptr;
  181.      int *recon_down_back_ptr;
  182. {
  183.   Pict *picture;
  184.   Macroblock *mblock;
  185.  
  186.   picture = &(curVidStream->picture);
  187.   mblock = &(curVidStream->mblock);
  188.  
  189.   ComputeVector(recon_right_back_ptr, recon_down_back_ptr,
  190.         mblock->recon_right_back_prev, 
  191.         mblock->recon_down_back_prev,
  192.         picture->back_f, picture->full_pel_back_vector,
  193.         mblock->motion_h_back_code, mblock->motion_v_back_code,
  194.         mblock->motion_h_back_r, mblock->motion_v_back_r); 
  195.  
  196. }
  197.